package com.xhblogs.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhblogs.book.mapper.BookMapper;
import com.xhblogs.book.pojo.Book;
import com.xhblogs.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;
    @Override
    public List<Map<String, Object>> getAll() {
        return bookMapper.getAll();
    }

    @Override
    public PageInfo<Map<String, Object>> getPageBook(Integer page, Integer pageSize) {
        // 开始分页
//1、调用PageHelper的startPage方法设置参数,其中page为当前页，size为每页显示条数
        PageHelper.startPage(page,pageSize);
//2、调用Mapper层查询全部的方法
        List<Map<String, Object>> all = bookMapper.getAll();
//3、构造pageInfo返回值
        return new PageInfo(all);
    }

    @Override
    public List<Map<String, Object>> getLike(String name) {
        return bookMapper.getLike(name);
    }

    @Override
    public List<Map<String, Object>> getCategoryIdBooks(int id) {
        return bookMapper.getCategoryIdBooks(id);
    }

    @Override
    public Book getIdBook(int id) {
        return bookMapper.getIdBook(id);
    }

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    public int addBook(Book book) {
        return bookMapper.addBook(book);
    }

    @Override
    public int deleteBook(int id) {
        return bookMapper.delectBook(id);
    }
}
